// pages/details/question/question.js
import Toast from '@vant/weapp/toast/toast';
import {
    request
} from '../../../utils/api';
import {
    gxcolumns
} from '../../../utils/columus.js';
Page({
    data: {
        show: false,
        columns: gxcolumns,
        message: [],
        userId: 0,
        flag: false
    },
    open() {
        this.setData({
            show: true
        })
    },
    cancel() {
        this.setData({
            show: false
        });
    },
    confirm(e) {
        this.setData({
            relationshipName: e.detail.value.text,
            relationship: e.detail.value.id,
        })
        this.cancel()
    },
    per() {
        wx.navigateBack()
    },
    async submit() {
        let res = await request({
            url: '/user/question',
            method: 'post',
            data: this.data
        })

        if (res.code == 200) {
            Toast.success('提交完成');
            if (this.data.userType == 0 && !this.data.flag) {
                setTimeout(() => {
                    wx.navigateBack({
                        delta: 4
                    })
                }, 500);
            } else {
                setTimeout(() => {
                    wx.navigateBack()
                }, 600);
            }
        } else {
            Toast.console.error('修改失败');
        }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        if (options.flag) {
            this.setData({
                flag: true
            })
        } else {
            this.setData({
                flag: false
            })
        }
        this.setData({
            userId: options.id
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    async onShow() {
        let res = await request({
            url: '/user/getQuestion?userId=' + this.data.userId,
            method: 'get'
        })
        this.data.columns.forEach(item => {
            if (res.result.relationship == item.id) {
                res.result.relationshipName = item.text
            }
        })
        this.setData(res.result)
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})